<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>下午茶生产查询列表</title>
    <!--{include file='comm/icheck.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div  class="search-box">
                <form id="searchForm" class="form-inline" onsubmit="return false;">
                    <div style="position:relative">
                        <span>
                            <span style='width:60px;text-align:right'>配送日期：</span>
                            <input type="text" class="form-control input-sm" style="width: 140px;" value="<!--{$currentDate}-->" name="send_date" id="send_date">
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送城市：</span>
                            <select id="deliver_cityid" name="deliver_cityid" class="form-control input-sm" style="width:100px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送站：</span>
                            <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>状态：</span>
                            <select name="bill_status" id="bill_status" class="form-control input-sm" style="width:110px;">
                                <option value="1">未生产</option>
                                <option value="">全部</option>
                                <option value="2">已生产</option>
                            </select>
                        </span>
                         <span>
                            <span style='width:60px;text-align:right'>订单编号：</span>
                            <input type="text" class="form-control input-sm" style="width:140px" value="" name="bill_code" id="bill_code">
                        </span>
                        <span>
                            <input type="button" class="btn btn-primary" value="查询" onclick="coupon.search();">&nbsp;&nbsp;
                            <label id="productID"><input type="button" class="btn btn-default" value="生产" onclick="coupon.produce();" id="productID">&nbsp;&nbsp;</label>
                            <input type="button" class="btn btn-warning btn-sm" value="重置" onclick="coupon.cz();">
                        </span>
                    </div>
                </form>
            </div>
            <input type="hidden" id="test"/>
            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">


    $('#send_date').datepicker();

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/production/coffeeSearch.ajax?operFlg=1&send_date="+$("#send_date").val()+"&bill_status=1",
        dataType: "json",
        colModel : [
            {display: "<input type=\"checkbox\" name=\"check_all\" onclick=\"CheckAll();\" id=\"check_all\" >", width : 80, align: 'center'},
            {display: "订单编号", width : 150, align: 'center'},
            {display: "状态", width : 120, align: 'center'},
            {display: "下单时间", width : 160, align: 'center'},
            {display: "到货时间", width : 200, align: 'left', name : "send_start_time",sortable : true},//mod by allen.qiang 20150204  1.生产管理-下午茶咖啡生产查询中 “到货时间”的排序未生效，请协助修改
            {display: "收货人姓名", width : 100, align: 'center'},//add by allen.qiang 20150204 2.另新增需求: 下午茶咖啡生产查询中需添加字段“收货人姓名”，用于咖啡制作的同事能根据此信息在咖啡杯上给客户书写个性化的问候
            {display: "配送站", width : 100, align: 'center'},
            {display: "商品明细", width : 600, align: 'left'}
        ],
        sortname: "createTime,send_start_time",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true
    });

    var coupon = {
        general_goods:{ },
        //查询
        search : function (){
            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        cz : function(){
            $("#deliver_cityid").val('');
            $('#distribution_id').val('');
            $('#bill_status').val('1');
            $('#bill_code').val('');
            $("#send_date").val('<!--{$currentDate}-->');
            $("#productID").html('<input type="button" class="btn btn-default" value="生产" onclick="coupon.produce();" id="productID">&nbsp;&nbsp;');

            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        produce : function(){
            var count=0;
            var check_ids = document.getElementsByName("check_id");
            for(var i=0; i<check_ids.length; i++){
                if(check_ids[i].checked){
                    var bill_code=check_ids[i].id.replace("Checked_","");
                    coupon.general_goods[i] = {
                        bill_code : bill_code
                    }
                    count++;
                }
            }
            var bill_status=$('#bill_status').val();
            if(bill_status!=1){
                E.alert("状态请选择未生产");
            }else if(count==0){
                E.alert("请选择要生产的单据");
            }else{
                E.confirm('您确认要生产选中的商品吗？',function(){
                    E.ajax_post({
                        url: "/invokingAjax-backend/production/coffeeSearch.ajax?operFlg=2",
                        data: {
                            general_goods:coupon.general_goods
                        },
                        call: function(data){
                            if(data.code=200){
                                E.alert('生产成功',2);
                                coupon.search();
                            }else{
                                E.alert(data.message);
                            }

                        }
                    });

                });

            }
        }
    };

    //全选
    function CheckAll(){
        var state = true;
        var textCheck = document.getElementById("test").value;
        if(textCheck=="0"){
            state = false;
            document.getElementById("test").value="1";
        }else{
            document.getElementById("test").value="0";
        }
        var check_ids = document.getElementsByName("check_id");
        for(var i=0; i<check_ids.length; i++){

            if(!check_ids[i].disabled){
                check_ids[i].checked = state;
            }
        }

    }

    $(window).ready(function() {

        $("#deliver_cityid").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    $.each(result_obj.data, function(i,val){
                        cityHtml +='<option value="'+val.id+'">'+val.name+'</option>';
                    });
                    $('#deliver_cityid').html(cityHtml);
                }else{
                    E.alert(result_obj.message);
                }
            }
        });

        //点击城市联动获得配送站(联动)
        $(document).on('change', '#deliver_cityid', function() {

            $('#distribution_id').html("");

            var cityID = $('#deliver_cityid').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            E.ajax_post({
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                data: {deliver_cityid: cityID},
                call: function( obj ) {
                    if(obj.code ==200 && obj.data != null){

                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                    }else{

                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                    }
                }
            });
        });

        //状态选择事件
        $(document).on('change', '#bill_status', function() {
            if($(this).val()!=1){
                $("#productID").html("");
            }else{
                $("#productID").html('<input type="button" class="btn btn-default" value="生产" onclick="coupon.produce();" id="productID">&nbsp;&nbsp;');
            }
            coupon.search();
        });
    });

</script>

</body>
</html>